package com.bookmarket.service.impl;

import com.bookmarket.dao.LLOrderMapper;
import com.bookmarket.entity.Custom;
import com.bookmarket.entity.Mess;
import com.bookmarket.entity.Order_Book;
import com.bookmarket.service.LLOrderService;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * LLOrderServiceImpl
 *
 * @author 李亮
 * @date 2018/1/3
 */

@Service("/orderService")
public class LLOrderServiceImpl implements LLOrderService {

@Resource
LLOrderMapper orderMapper;


    public Map getlist(Map<String, Object> cond){
        Page page = new Page();
        page.setTotal(orderMapper.getcount(cond));
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(curPageNum);
        int zong=  (int) (page.getTotal() / pageSize + (page.getTotal() % pageSize == 0 ? 0 : 1));
        List<Map> list = orderMapper.getOrder(cond);
        for(Map m:list){
            List list1=orderMapper.getOrder_Book((int)m.get("id"));
           m.put("list1",list1);
        }
        Map map = new HashMap();
        map.put("list",list);
        map.put("totlpage",zong);
        return map;
    }
    public Map getlist2(Map<String, Object> cond){
        Page page = new Page();
        page.setTotal(orderMapper.getcount(cond));
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(curPageNum);
        int zong=  (int) (page.getTotal() / pageSize + (page.getTotal() % pageSize == 0 ? 0 : 1));
        List<Map> list = orderMapper.getOrder2(cond);
        Map map = new HashMap();
        map.put("list",list);
        map.put("totlpage",zong);
        return map;
    }
    public void update(int id,int stu){
        orderMapper.update(id,stu);
    };
    public int sel(int id){
        return orderMapper.sel(id);
    }
    public Map getmess(Map<String, Object> cond){
        Page page = new Page();
        page.setTotal(orderMapper.getcoun(cond));
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(curPageNum);
        int zong=  (int) (page.getTotal() / pageSize + (page.getTotal() % pageSize == 0 ? 0 : 1));
        List<Mess> list = orderMapper.getmess(cond);
        Map map = new HashMap();
        map.put("list",list);
        map.put("totlpage",zong);
        return map;
    }
    public void dellmess(int id){
        orderMapper.dellmess(id);
    }
    public void updatecus(Custom custom){ orderMapper.updatecus(custom);}
    public void addmess(Mess mess){
        orderMapper.addmess(mess);
    }
    public void dell(int id){
        orderMapper.dell(id);
    }
    public Order_Book getord(int id){
        return  orderMapper.getord(id);
    }


    public LLOrderMapper getOrderMapper() {
        return orderMapper;
    }

    public void setOrderMapper(LLOrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }
}